<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/9/27
 * Time: 17:58
 */
namespace app\portal\controller;

use app\portal\model\PortalCategoryModel;
use cmf\controller\HomeBaseController;
use think\Db;

class AboutController extends HomeBaseController
{
    public function index()
    {
        $banner=Db::name('slide_item')->where("slide_id",3)->where('status',1)->order('list_order asc')->limit(0,4)->select();
        foreach ($banner as $k=>$v){
            $img="img".$k;
            $this->assign("{$img}",$v);
        }
        $id                = $this->request->param('cid', 0, 'intval');

        $portalCategoryModel = new PortalCategoryModel();


        $category = $portalCategoryModel->where('id', $id)->where('status', 1)->find();
        $this->assign('category', $category);
        //   echo $portalCategoryModel->getLastSql();
       $product=Db::name("portal_post")->alias("b")
           ->join("portal_category_post a",'a.post_id=b.id')->where("a.category_id",$category['id'])->select();
       // print_r($product);exit;
        $list=array();
        foreach ($product as $k=>$v){
            $v['more']=json_decode($v['more'],true);
            if(strpos($v['more']['thumbnail'],'http') === false) {
                $list[$k]['more']['thumbnail']="/public/upload/".$v['more']['thumbnail'];
            }else{
                $list[$k]['more']['thumbnail']=$v['more']['thumbnail'];
            }
            $list[$k]['name']=$v['post_title'];
            $list[$k]['id']=$v['id'];
            $list[$k]['post_id']=$v['post_id'];
        }

        $this->assign('list', $list);
        return $this->fetch(':about');
    }
}